import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.*;

public class PlayerList extends HttpServlet
{

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        String dbUser = "jh3240"; // enter your username here
        String dbPassword = "kuzifQbw"; // enter your password here

        try
        {
            OracleDataSource ods = new oracle.jdbc.pool.OracleDataSource();
            ods.setURL("jdbc:oracle:thin:@//w4111g.cs.columbia.edu:1521/ADB");
            ods.setUser(dbUser);
            ods.setPassword(dbPassword);

            Connection conn = ods.getConnection();

            String query = new String();
            String query2 = new String();

            Statement s = conn.createStatement();

            String name = request.getParameter("name");

            query = "select p.playerid from players p where p.name = '" + name + "'";

            ResultSet r = s.executeQuery(query);
            boolean found = false;
            while (r.next())
            {
                found = true;
                out.println("<a href=\"/player?pid=" + r.getString("playerid") + "\">" + name + "</a><br />");
            }
            if (!found)
            {
                out.println("No player found with name \"" + name + "\".");
            }

            r.close();

            s.close();

            conn.close();

        }
        catch (Exception e)
        {
            out.println("The database could not be accessed.<br>");
            out.println("More information is available as follows:<br>");
            e.printStackTrace(out);
        }

    } // end doGet method

} // end DatabaseServlet class

